package com.sjz.han.industry.activites;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sjz.han.industry.R;
import com.sjz.han.industry.base.BaseActivity;
import com.sjz.han.industry.entities.WaitJhMemberDetailEntity;
import com.sjz.han.industry.internetmanage.ReqestUrl;
import com.sjz.han.industry.utils.JsonUtils;
import com.sjz.han.industry.utils.PicUtils;
import com.sjz.han.industry.utils.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

//会员详情
public class MemberDetailActivity extends BaseActivity implements View.OnClickListener{
    private String userId="";

    private ImageView hyxq_photo_img;
    private TextView hyxq_name_tv,hyxq_level_tv,hyxq_phone_tv,
            hyxq_adress_tv,hyxq_zctime_tv,hyxq_hybh_tv,hyxq_yqm_tv,
            hyxq_bankname_tv,hyxq_bankcode_tv;
    @Override
    protected int setLayoutId() {
        return R.layout.activity_memberdetail;
    }

    @Override
    protected void initDatas() {
        userId=getIntent().getStringExtra("userId");
        getMsg();
    }

    @Override
    protected void initViews() {
        reback_btn=(RelativeLayout)this.findViewById(R.id.reback_btn);
        titleTv=(TextView)this.findViewById(R.id.ctitle_tv);
        titleTv.setText("会员信息");
        hyxq_photo_img=(ImageView)this.findViewById(R.id.hyxq_photo_img);

        hyxq_name_tv=(TextView)this.findViewById(R.id.hyxq_name_tv);
                hyxq_level_tv=(TextView)this.findViewById(R.id.hyxq_level_tv);
                hyxq_phone_tv=(TextView)this.findViewById(R.id.hyxq_phone_tv);
                hyxq_adress_tv=(TextView)this.findViewById(R.id.hyxq_adress_tv);
                hyxq_zctime_tv=(TextView)this.findViewById(R.id.hyxq_zctime_tv);
                hyxq_hybh_tv=(TextView)this.findViewById(R.id.hyxq_hybh_tv);
                hyxq_yqm_tv=(TextView)this.findViewById(R.id.hyxq_yqm_tv);
                hyxq_bankname_tv=(TextView)this.findViewById(R.id.hyxq_bankname_tv);
                hyxq_bankcode_tv=(TextView)this.findViewById(R.id.hyxq_bankcode_tv);
    }

    @Override
    protected void setLisener() {
        reback_btn.setOnClickListener(this);
    }

    @Override
    protected void onRetry() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.reback_btn:
                finish();
                break;
        }
    }
    public void getMsg(){
        OkHttpUtils
                .post()
                .url(ReqestUrl.DJH_HYDTAIL_URL)
                .addParams("token",shareUtils.getToken())
                .addParams("userId",userId)
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                ToastUtils.popUpToast("请求超时");
            }
            @Override
            public void onResponse(String response, int id) {
                if(ReqestUrl.rebacRequestJson(response)!=null){
                    WaitJhMemberDetailEntity entity= JsonUtils.getObject(response,WaitJhMemberDetailEntity.class);
                    if(entity!=null&&entity.code==0&&entity.data!=null){
                        if("1".equals(shareUtils.getLevel())){
                            hyxq_level_tv.setText("等级：普通会员");
                        }else if("2".equals(shareUtils.getLevel())){
                            hyxq_level_tv.setText("等级：A级会员");
                        }else if("3".equals(shareUtils.getLevel())){
                            hyxq_level_tv.setText("等级：B级会员");
                        }else if("4".equals(shareUtils.getLevel())){
                            hyxq_level_tv.setText("等级：一级会员");
                        }else if("5".equals(shareUtils.getLevel())){
                            hyxq_level_tv.setText("等级：二级会员");
                        }else if("6".equals(shareUtils.getLevel())){
                            hyxq_level_tv.setText("等级：三级会员");
                        }

                        hyxq_name_tv.setText(entity.data.username);
                        hyxq_zctime_tv.setText("注册时间："+entity.data.excelCreateTime);
                        hyxq_phone_tv.setText("联系电话："+entity.data.phone);
                        hyxq_bankname_tv.setText("收款银行："+entity.data.bankName);
                        hyxq_bankcode_tv.setText("银行账户："+entity.data.bankCode);
                        hyxq_yqm_tv.setText("邀  请  码 ："+entity.data.inviteCode);
                        hyxq_adress_tv.setText("所在位置："+entity.data.address);
                        hyxq_hybh_tv.setText("会员编号："+entity.data.userId);
                        PicUtils.showImageViewToCircle(MemberDetailActivity.this, R.mipmap.ic_wd_tx, ReqestUrl.BASE+entity.data.photo, hyxq_photo_img);
                    }else{
                        ToastUtils.popUpToast(entity.msg);
                    }
                }
            }
        });
    }
}
